package com.five.admin.controller;

import com.five.admin.service.CarouselService;
import com.five.controller.BaseController;
import com.five.admin.service.StatisticsService;
import com.five.entity.User;
import com.five.entity.qo.CourseSalesVolume;
import com.five.entity.qo.SalesAmount;
import com.five.vo.BaseResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: star
 * @Date: 2021-05-21 14:36
 *
 * 统计   Controller层
 */
@Controller
@RequestMapping("statistics")
@Api("统计业务层接口")
@CrossOrigin
public class StatisticsController extends BaseController {

    @Autowired
    private StatisticsService statisticsService;

    @ResponseBody
    @RequestMapping(value = "index",method = RequestMethod.GET)
    @ApiOperation("后台统计接口")
    public BaseResultVO indexCounts(){
        Map resultMap = new HashMap();
        resultMap.put("revenueByToday",statisticsService.countRevenueByToday());
        resultMap.put("userNumber",statisticsService.countUserNumber());
        resultMap.put("chapterView",statisticsService.countChapterView());
        resultMap.put("courseNumber",statisticsService.countCourseNumber());
        return successResp(resultMap);
    }

    @ResponseBody
    @RequestMapping(value = "courseSales",method = RequestMethod.GET)
    @ApiOperation("统计销量前五的课程")
    public BaseResultVO courseSales(){
        List<CourseSalesVolume> carouselServices = statisticsService.countCourseSalesVolumeTOP5();
        return successResp(carouselServices);
    }

    @ResponseBody
    @RequestMapping(value = "salesAmount",method = RequestMethod.GET)
    @ApiOperation("统计近7天销售额")
    public BaseResultVO SalesAmount(){
        List<SalesAmount> salesAmounts = statisticsService.countSalesAmountBeforeSevenDay();
        return successResp(salesAmounts);
    }
}
